<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('法律问答--问题列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 70px;">问题标题：</label>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="business:question:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editFull()" shiro:hasPermission="business:question:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:question:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:question:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var listFlag = [[${@permission.hasPermi('business:question:list')}]];

        var editFlag = [[${@permission.hasPermi('business:question:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:question:remove')}]];
        var examineStatusDatas = [[${@dict.getType('approval_status')}]];
        var screenStatusDatas = [[${@dict.getType('shield_status')}]];
        var userList = [[${userList}]];
        var prefix = ctx + "business/question";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "法律问答--问题",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'questionId',
                    title: '问题id',
                    visible: false
                },
                {
                    field: 'userId',
                    title: '用户',
                    formatter: function(value, row, index) {
                        var datas = userList;
                        if ($.common.isEmpty(datas) || $.common.isEmpty(value)) {
                            return '';
                        }
                        var actions = [];
                        $.each(datas, function(indexs, dict) {
                            if (dict.userId == ('' + value)) {
                                var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass;
                                actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dict.userName));
                                return false;
                            }
                        });
                        return actions.join('');
                    }
                },
                {
                    field: 'title',
                    title: '问题标题',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 5, "open");
                    }
                },
                {
                    field: 'content',
                    title: '问题详情',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 5, "open");
                    }
                },
                {
                    field: 'examineStatus',
                    title: '审核状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(examineStatusDatas, value);
                    }
                },
                {
                    field: 'screenStatus',
                    title: '屏蔽状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(screenStatusDatas, value);
                    }
                },
                // {
                //     field: 'repliesNumber',
                //     title: '回复数量'
                // },
                // {
                //     field: 'readNumber',
                //     title: '阅读数量'
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="audit(\'' + row.questionId + '\')"><i class="fa fa-edit"></i>审核</a> ');

                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.questionId + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="info(\'' + row.questionId + '\')"><i class="fa fa-edit"></i>详情</a> ');

                        // actions.push('<a class="btn btn-success btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="info(\'' + row.questionId + '\')"><i class="fa fa-edit"></i>回答列表</a> ');

                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.questionId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function audit(questionId) {
            var url = prefix + '/audit/' + questionId;
            $.modal.open("审批", url);
        }
        function info(questionId) {
            var url = prefix + '/info/' + questionId;
            $.modal.openTab("详情", url);
        }
    </script>
</body>
</html>